public class RegularEmployee extends Employee {
    private double hourlyRate, hoursWorked;

    public RegularEmployee(String name, String id, double hourlyRate, double hoursWorked) {
        super(name, id);
        this.hourlyRate = hourlyRate;
        this.hoursWorked = hoursWorked;
    }

    @Override
    public double calculateSalary() throws WorkTimeException {
        validateHoursWorked();
        double salary = hoursWorked * hourlyRate;
        if (hoursWorked > 160) salary += (hoursWorked - 160) * hourlyRate * 0.5;
        return salary;
    }

    private void validateHoursWorked() throws WorkTimeException {
        if (hoursWorked < 0) throw new WorkTimeException("工作时长不能为负数");
        if (hoursWorked > 300) throw new WorkTimeException("工作时长超出合理范围");
    }

    @Override
    protected String getPosition() { return "普通员工"; }

    public void setHourlyRate(double hourlyRate) { this.hourlyRate = hourlyRate; }
    public void setHoursWorked(double hoursWorked) throws WorkTimeException {
        this.hoursWorked = hoursWorked;
        validateHoursWorked(); // 立即验证
    }
    public double getHoursWorked() { return hoursWorked; }
}